﻿using zijian666.WorkScheduler.Abstractions;


namespace zijian666.WorkScheduler.Defaults;

/// <summary>
/// 默认的令牌过期策略
/// </summary>
/// <param name="expires">过期时间间隔</param>
public class ExpirationPolicy(TimeSpan expires) : IExpirationPolicy
{
    private readonly TimeSpan _expires = expires;

    /// <summary>
    /// 是否已过期
    /// </summary>
    public bool IsExpired(IToken token)
    {
        return token is null
            || token.Cancellation.IsCancellationRequested
            || DateTimeOffset.UtcNow - token.LastActiveTime > _expires;
    }
}
